package com.sgl.config.googleSecurity;

import com.sgl.config.shiro.ShiroUtil;
import com.sgl.entity.User;
import com.sgl.util.ReturnData;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/google")
public class GoogleSecController {
    /**
     * 谷歌身份验方法  用于审核的时候 确认审核人的身份信息 来通过审核订单
     * @param code 谷歌验证码
     * @return json 返回体
     */
    @RequestMapping("/check")
    public ReturnData check(String code){
        User user = ShiroUtil.getUser();
        if (user.getRole()==1){
            return new ReturnData().failBack("您无法审核此订单，请联系高权限管理员进行审核。");
        }
        String key = user.getGoogleKey();
        long time = System.currentTimeMillis ();
        GoogleAuthenticatorUtil g = new GoogleAuthenticatorUtil();
        boolean result = g.check_code (key,code,time);
        if (!result){
            return new ReturnData().failBack("安全码错误请重新输入");
        }
        return new ReturnData().okBack();
    }
}
